package com.xhu.collegestudentrentalsystem.module.user.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhu.collegestudentrentalsystem.module.user.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;

/**
 * @author zhu huilin
 * @date 2023/2/21 19:45
 */
public interface UserDAO extends BaseMapper<User> {

    /**
     * 修改用户部分字段的信息（包含头像）
     */
    @Update("UPDATE user " +
            " SET" +
            " username = #{username} , " +
            " user_display_na = #{userDisplayNa} , " +
            " phone = #{phone} , " +
            " email = #{email} , " +
            " id_card = #{idCard} , " +
            " user_head = #{userHead} , " +
            " user_desc = #{userDesc} , " +
            " sex = #{sex} , " +
            " hobby = #{hobby} , " +
            " job = #{job}" +
            " WHERE id = #{id} ")
    public Integer updateUserInfoAndHead(User user);

    /**
     * 修改用户部分字段的信息（不包含头像）
     */
    @Update("UPDATE user " +
            " SET" +
            " username = #{username} , " +
            " user_display_na = #{userDisplayNa} , " +
            " phone = #{phone} , " +
            " email = #{email} , " +
            " id_card = #{idCard} , " +
            " user_desc = #{userDesc} , " +
            " sex = #{sex} , " +
            " hobby = #{hobby} , " +
            " job = #{job}" +
            " WHERE id = #{id} ")
    public Integer updateUserInfo(User user);

    /**
     * 更改用户状态值
     */
    @Update("update user set status = #{status} where id = #{userId}")
    public Integer updateUserStatus(@Param("userId") Long userId,@Param("status") Integer status);

    /**
     * 根据ID更改用户密码
     */
    @Update("update user set password = #{password} where id = #{userId}")
    public Integer updateUserPass(@Param("userId") Long userId, @Param("password") String password);

    /**
     * 根据邮箱修改密码
     */
    @Update("update user set password = #{password} where email = #{email}")
    public Integer updateUserPassByEmail(@Param("email")String email, @Param("password")String password);
}
